package com.suse.warmstill.controller;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;
import com.suse.warmstill.common.exception.BusinessException;
import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.common.utils.FileTypeUtils;
import com.suse.warmstill.common.utils.FileUtils;
import com.suse.warmstill.config.OssConfig;
import com.suse.warmstill.service.CosService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.UUID;

/**
 * @author 黄靖
 * @author 2022-11-04 18:31
 * description:
 **/
@Api(tags = "文件上传")
@RestController
@Slf4j
@RequestMapping("/warmstill/cos")
public class CommonCosApi {
    @Resource
    private CosService cosService;

    @Autowired
    private OssConfig ossConfig;

    /**
     * 上传到腾讯云服务器（https://cloud.tencent.com/document/product/436/10199）
     *
     * @return
     */
    @ApiOperation("上传单文件到 腾讯云,同时返回 照片的地址，可以直接通过照片访问")
    @PostMapping(value = "/upload")
    @ResponseBody
    public CallResult upload(@RequestParam(value = "file") MultipartFile file) {

        final String s = cosService.uoloadFile(file);
        return CallResult.success(s);
    }


}
